/**
 * @author		Ben Layet
 * @version 	0.1
 * @date		3 Sep 2008
 * @copyright 	� Canon Europa N. V. 2004
 */
package org.learnaholic.ui.itemtable;

import java.awt.Color;
import java.awt.Font;

import javax.swing.BorderFactory;
import javax.swing.JTextField;

/**
 * 
 */
public class TableCell extends JTextField
{
	private Color selectedBackground = new Color(0x000055);
	private Color nonSelectedBackground = new Color(0xffffff);
	private Color selectedForeground = new Color(0xffffff);
	private Color nonSelectedForeground = new Color(0x000055);
	
	
	public Color getSelectedBackground()
	{
		return selectedBackground;
	}

	public void setSelectedBackground(Color selectedBackground)
	{
		this.selectedBackground = selectedBackground;
		setSelected(selected);
	}

	public Color getNonSelectedBackground()
	{
		return nonSelectedBackground;
	}

	public void setNonSelectedBackground(Color nonSelectedBackground)
	{
		this.nonSelectedBackground = nonSelectedBackground;
		setSelected(selected);
	}

	public Color getSelectedForeground()
	{
		return selectedForeground;
	}

	public void setSelectedForeground(Color selectedForeground)
	{
		this.selectedForeground = selectedForeground;
		setSelected(selected);
	}

	public Color getNonSelectedForeground()
	{
		return nonSelectedForeground;
	}

	public void setNonSelectedForeground(Color nonSelectedForeground)
	{
		this.nonSelectedForeground = nonSelectedForeground;
		setSelected(selected);
	}

	private boolean selected = false;
//	private final Font font = new Font("MS Mincho", Font.BOLD , 40);
	
	public TableCell(String label)
	{
		super(label);
		super.setOpaque(true);
//		super.setFont(font);
		super.setHorizontalAlignment(LEFT);
		setSelected(false);
		setEditable(false);
		setBorder(BorderFactory.createEmptyBorder());
	}
	
	public void setSelected(boolean selected)
	{
		this.selected = selected;
		super.setBackground(selected?selectedBackground:nonSelectedBackground);
		super.setForeground(selected?selectedForeground:nonSelectedForeground);
	}
	
	

	public void setSize(int width, int height)
	{
		setFont(new Font("MS Mincho", Font.BOLD, height/2));
		super.setSize(width, height);
	}
	public void setBounds(int x, int y, int width, int height)
	{
		setFont(new Font("MS Mincho", Font.BOLD, height/2));
		super.setBounds(x, y, width, height);
	}
	
	/**
	 * @return
	 */
	public boolean isSelected()
	{
		return selected;
	}

	/**
	 * @return
	 */
	public String getId()
	{
		return getText();
	}
	
}
